package Test1;

import java.util.List;

/**
 * 单元测试类 - 测试四则运算功能
 */
public class ExpressionGeneratorTest {

    public static void main(String[] args) {
        testPureMultiplication();
        testPureDivision();
        testMixedOperations();
        testThreeNumberOperations();
        System.out.println("所有测试通过！");
    }

    public static void testPureMultiplication() {
        System.out.println("测试纯乘法...");
        ExpressionGenerator generator = new ExpressionGenerator();
        List<Expression> expressions = generator.generateExpressions(ExpressionGenerator.PURE_MULTIPLICATION_2, 10);

        assert expressions.size() == 10 : "应该生成10个表达式";

        for (Expression expr : expressions) {
            assert "×".equals(expr.getOp1()) : "应该是乘法操作";
            assert expr.getResult() > 0 : "结果应该大于0";
            assert expr.getResult() < 100 : "结果应该小于100";
            assert expr.isIntegerResult() : "结果应该是整数";
        }
        System.out.println("✓ 纯乘法测试通过");
    }

    public static void testPureDivision() {
        System.out.println("测试纯除法...");
        ExpressionGenerator generator = new ExpressionGenerator();
        List<Expression> expressions = generator.generateExpressions(ExpressionGenerator.PURE_DIVISION_2, 10);

        assert expressions.size() == 10 : "应该生成10个表达式";

        for (Expression expr : expressions) {
            assert "÷".equals(expr.getOp1()) : "应该是除法操作";
            assert expr.getResult() > 0 : "结果应该大于0";
            assert expr.getResult() < 100 : "结果应该小于100";
            assert expr.isIntegerResult() : "结果应该是整数";
        }
        System.out.println("✓ 纯除法测试通过");
    }

    public static void testMixedOperations() {
        System.out.println("测试四则混合运算...");
        ExpressionGenerator generator = new ExpressionGenerator();
        List<Expression> expressions = generator.generateExpressions(ExpressionGenerator.MIXED_4_OPERATIONS_2, 20);

        assert expressions.size() == 20 : "应该生成20个表达式";

        for (Expression expr : expressions) {
            assert expr.getResult() > 0 : "结果应该大于0";
            assert expr.getResult() < 100 : "结果应该小于100";
            assert expr.isIntegerResult() : "结果应该是整数";
        }
        System.out.println("✓ 四则混合运算测试通过");
    }

    public static void testThreeNumberOperations() {
        System.out.println("测试三个数混合运算...");
        ExpressionGenerator generator = new ExpressionGenerator();
        List<Expression> expressions = generator.generateExpressions(ExpressionGenerator.MIXED_4_OPERATIONS_3, 5);

        assert expressions.size() == 5 : "应该生成5个表达式";

        for (Expression expr : expressions) {
            assert expr.getNum3() != null : "应该是三个数的表达式";
            assert expr.getResult() > 0 : "结果应该大于0";
            assert expr.getResult() < 100 : "结果应该小于100";
            assert expr.isIntegerResult() : "结果应该是整数";
            if (expr.getIntermediateResult() != null) {
                assert expr.getIntermediateResult() > 0 : "中间结果应该大于0";
                assert expr.getIntermediateResult() < 100 : "中间结果应该小于100";
            }
        }
        System.out.println("✓ 三个数混合运算测试通过");
    }
}